using ExtendedMvc.Ajax;
using ExtendedMvc.Html;

namespace ExtendedMvc.Elements {
	public class SubmitButton : ButtonBase<SubmitButton> {
		private bool _skipValidation;
		private string _formId;

		public SubmitButton(string caption, string formId, string name = null, string id = null)
			: base(HtmlButtonType.Submit, caption, name, id) {
			_formId = formId;
		}

		public virtual SubmitButton SkipValidation(bool value = true) {
			_skipValidation = value;
			return this;
		}

		protected override void Prepare() {
			OnClick(string.Format(_skipValidation ? JavaScriptHelper.Submit : JavaScriptHelper.SubmitWithValidation, _formId));
			base.Prepare();
		}
	}
}